home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 2D / TickAnimate / TickAnimate.p < prev    next >
Encoding:
Text File  |  2000-09-28  |  3.5 KB  |  121 lines  |  [TEXT/CWIE]

  1. {
  2.     File:        TickAnimate.p
  3.  
  4.     Contains:    This uses ticks to time and speed control a very simple animation
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1984-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/14/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. }
  23. PROGRAM ReleaseTst;
  24.  
  25. USES    Quickdraw,Memory,ToolUtils,Resources,Dialogs,OSUtils,Retrace,Fonts,Events,
  26.         Windows,menus;
  27.  
  28. CONST
  29.     iAnimate = 1;
  30.     iQuit = 2;
  31.     iUser1 = 3;
  32.     iUser2 = 4;
  33.     
  34. VAR
  35.     MyDialog : DialogPtr;
  36.     theRect : rect;
  37.     animating,quit : boolean;
  38.     Counter : byte;
  39.     item : handle;
  40.     err,itemType,itemHit : integer;
  41.     CurTicks : longint;
  42.     theEvent : EventRecord;
  43.  
  44. {------------------------------------------------------------------------------------}
  45.  
  46. PROCEDURE InitMac;
  47.  
  48. BEGIN                       {InitMac}
  49.  
  50.     InitGraf(@qd.thePort);                {initialize QuickDraw}
  51.     InitFonts;                           {initialize Font Manager}
  52.     FlushEvents(everyEvent, 0);        {call OS Event Mgr to discard any previous events}
  53.     InitWindows;                       {initialize Window Manager}
  54.     InitMenus;                           {initialize Menu Manager}
  55.     TEInit;                            {initialize TextEdit}
  56.     InitDialogs(NIL);                   {initialize Dialog Manager}
  57.     InitCursor;                        {call QuickDraw to make cursor (pointer) an arrow}
  58.     quit := false;                        {always initialize them booleans!}
  59.     animating := false;
  60.     Counter := $21;
  61.  
  62. END;                       {InitMac}
  63.  
  64. {------------------------------------------------------------------------------------}
  65.  
  66. BEGIN                              {main PROGRAM}
  67.     
  68.     InitMac;
  69.     MyDialog := GetNewDialog (1,nil,pointer(-1));
  70.     if MyDialog <> nil then
  71.     begin
  72.         SetPort(MyDialog);
  73.         GetDialogItem (MyDialog,iUser1,itemType,item,theRect);
  74.         FrameRect (theRect);
  75.         TextFont (kFontIDHelvetica);
  76.         TextSize (14);
  77.         moveTo ((theRect.topleft.h)+10,(theRect.topleft.v)+15);
  78.         DrawString ('Welcome To TickAnimator');
  79.         GetDialogItem (MyDialog,iUser2,itemType,item,theRect);
  80.         FrameRect (theRect);
  81.         insetRect (theRect,3,3);
  82.         TextFont (kFontIDHelvetica);
  83.         TextSize (24);
  84.         moveTo ((theRect.topleft.h)+10,(theRect.topleft.v)+20);
  85.         DrawString ('Cameron Birse - 1990');
  86.         SetFontLock (true);
  87.         err := noerr;
  88.         CurTicks := tickcount;
  89.         repeat
  90.             if WaitNextEvent (EveryEvent,theEvent,1,nil) then
  91.             if isDialogEvent (theEvent) then
  92.             if DialogSelect (theEvent,MyDialog,itemHit) then
  93.             case itemHit of
  94.                 iAnimate : if not animating then animating := true else
  95.                             if animating then 
  96.                             begin
  97.                                 eraseRect (theRect);
  98.                                 moveTo ((theRect.topleft.h)+10,(theRect.topleft.v)+20);
  99.                                 DrawString ('Cameron Birse - 1990');
  100.                                 animating := false;
  101.                             end;
  102.                 iQuit : quit := true;
  103.             end; {case}
  104.             if CurTicks < (TickCount-8) then
  105.             begin
  106.                 CurTicks := TickCount;
  107.                 if animating then
  108.                 begin
  109.                     eraseRect (theRect);
  110.                     moveTo ((theRect.topleft.h)+10,(theRect.topleft.v)+20);
  111.                     DrawChar (char(Counter));
  112.                     Counter := Counter + 1;
  113.                     if Counter > $AA then Counter := $21;
  114.                 end;
  115.             end;
  116.         until quit;
  117.         SetFontLock (false);
  118.         TextFont (systemFont);
  119.         TextSize (12);
  120.     end;
  121. END.